<template>
  <HomePanel ref="target" title="人气推荐" sub-title="人气推荐 不容错过">
    <!-- 面板内容 -->
    <div class="home-hot">

      <Transition name="fade">
        <ul class="goods-list" v-if="hotList.length">
          <li v-for="item in hotList" :key="item.id">
            <RouterLink to="/">
              <img :src="item.picture" />
              <p class="name ellipsis">{{item.title}}</p>
              <p class="desc">{{item.alt}}</p>
            </RouterLink>
          </li>
        </ul>

        <HomeSkeleton v-else></HomeSkeleton>
      </Transition>

    </div>
  </HomePanel>
</template>

<script>
import { getHotAPI } from '@/api/category'
import HomePanel from './home-panel'
import { ref } from 'vue'
import { useLazyDateFn } from '@/utils/hooks'

export default {
  name: 'HomeNew',
  components: { HomePanel },
  setup() {
    // 数据懒加载  开始
    // useLazyDateFn是自定义的一个函数,能够懒加载传入的api
    const { list, target } = useLazyDateFn(getHotAPI)
    const hotList = ref(list)
    // 数据懒加载  结束
    return { hotList, target }
  }
}
</script>

<style scoped lang="less">
.home-hot {
  position: relative;
  height: 426px;
}
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    transition: all 0.5s;
    &:hover {
      transform: translate3d(0, -3px, 0);
      box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
    }
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .desc {
      color: #999;
      font-size: 18px;
    }
  }
}
</style>